<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="车辆照片代码:" prop="pictureNo">
          <el-input
            v-model="formModel.pictureNo"
            class="filter-item filter-200"
            clearable
          />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" v-if="hasPermission('photos_select')" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission('photos_upload')" plain @click="handleAdd">照片上传</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :columns="columns" :auto-width="false" @row-click="handleRowClick" :is-radio="true">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="120"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span class="hey_tools_btn" v-if="hasPermission('photos_edit')" @click="handleEdit(row)">编辑</span>
            <span class="hey_tools_btn" v-if="hasPermission('photos_del')" @click="handleDelete(row)">删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <div class="imageDiv" v-if="showImage">
      <h3>照片预览:</h3>
      <img class="image" :src="imageSrc" style="width:30%;height:30%">
    </div>
    <el-dialog
      v-dialogDrag
      v-if="dialogVisible"
      :close-on-click-modal="false"
      title="整车照片上传"
      :visible.sync="dialogVisible"
      width="50%"
    >
      <vehicle-photos-info-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>

  </div>
</template>

<script>
export default {
  name: 'VehiclePhotosInfoList',
  components: {
    VehiclePhotosInfoMnt: () => import('./vehicle-photos-info-mnt')
  },
  props: {},
  data() {
    return {
      imageSrc:'',
      showImage:false,
      dialogVisible: false,
      operType: '',
      editData: {},
      formModel: {
        isDelete: '0',
        pictureNo: '',
      },
      columns: [
        { title: '车辆照片代码', key: 'pictureNo' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '最后修改时间', key: 'lastUpdateTime'},
        { title: '最后修改人', key: 'lastUpdateUsername' },
      ]
    }
  },
  computed: {},
  mounted() {

  },
  methods: {
    handleRowClick(row) {
      if (row) {
        this.showImage = true
        this.imageSrc = 'data:image/jpeg;base64,'+row.picture
      } else {
        this.showImage = false
        this.imageSrc = ''
      }
    },
    queryList() {
      this.showImage = false
      this.imageSrc = ''
      this.$refs.table.query('/tmBasPhotos/queryTmBasPhotos', this.formModel, '', false)
    },
    handleAdd() {
      this.operType = 'add'
      this.dialogVisible = true
    },
    handleEdit(row) {
      this.dialogVisible = true
      this.operType = 'edit'
      this.editData = row || {}
    },
    handleDelete(row) {
      this.$sure('确认删除？', _ => {
        // FormData 对象
        var form = new FormData();
        // 文件对象
        const tmBasPhotosId = row.tmBasPhotosId
        const operateType = '03'
        form.append("tmBasPhotosId", tmBasPhotosId);
        form.append("operateType", operateType);
        this.post('/tmBasPhotos/maintainTmBasPhotos', form).then(res => {
          this.$info('删除成功', this.queryList)
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .imageDiv{
    padding-top:20px;
  }
  .image{
    padding-top:10px;
  }
</style>
